package entity

import (
	"mime/multipart"
	common_entity "trpg-common/entity"
	"trpg-common/utils/time_util"
)

type User struct {
	common_entity.BaseEntity
	Uid        string `gorm:"column:uid" json:"uid"`
	Phone      string `gorm:"column:phone" json:"phone"`
	Username   string `gorm:"column:username" json:"username"`
	Password   string `gorm:"column:password" json:"password"`
	AvatarPath string `gorm:"column:avatar_path;default:/avatar/default_avatar.jpg" json:"-"`
	AvatarUrl  string `gorm:"-" json:"avatar"`
	Session    string `gorm:"-" json:"session"`
}

func (User) TableName() string {
	return "user"
}

type Character struct {
	common_entity.BaseEntity
	Uid               string `gorm:"column:uid" json:"uid"`
	CharacterName     string `gorm:"column:character_name" json:"characterName"`
	Name              string `gorm:"column:name" json:"name"`
	RememberedVarsStr string `gorm:"column:remembered_vars_str" json:"rememberedVars"`
	RememberedVars    string `gorm:"column:remembered_vars" json:"-"`
	ExcelUrl          string `gorm:"-" json:"excelUrl"`
	ExcelPath         string `gorm:"column:excel_path" json:"excelPath"`
}

func (Character) TableName() string {
	return "character"
}

type Scripts struct {
	common_entity.BaseEntity
	Name        string   `gorm:"column:name" json:"name" form:"name"`
	Description string   `gorm:"column:description" json:"description" form:"description"`
	CoverUrl    string   `gorm:"-" json:"coverUrl"`                                // 封面在oss中的url
	ContentUrl  string   `gorm:"-" json:"contentUrl"`                              // 文件内容在oss中的url
	LabelIds    string   `gorm:"column:label_ids" json:"labelIds" form:"labelIds"` // 标签id
	LabelNames  []string `gorm:"-" json:"labelNames"`                              // 标签名
	LabelIdsArr []int64  `gorm:"-" json:"labelIdsArr"`
	CoverKey    string   `gorm:"column:cover_key" json:"coverKey"`
	ContentKey  string   `gorm:"column:content_key" json:"contentKey"`
}

func (Scripts) TableName() string {
	return "scripts"
}

type Label struct {
	common_entity.BaseEntity
	Name string `gorm:"column:name" json:"name"`
	Type int32  `gorm:"column:type" json:"type"` // 0:剧本标签; 1:房间标签
}

func (Label) TableName() string {
	return "label"
}

type ScriptsCollection struct {
	common_entity.BaseEntity
	ScriptId int64  `gorm:"column:script_id" json:"scriptId"`
	Uid      string `gorm:"column:uid" json:"uid"`
}

func (ScriptsCollection) TableName() string {
	return "scripts_collection"
}

type Room struct {
	common_entity.BaseEntity
	Name         string   `gorm:"column:name" json:"name" form:"name"`
	Description  string   `gorm:"column:description" json:"description" form:"description"`
	Admin        string   `gorm:"admin" json:"admin" form:"admin"`
	CoverUrl     string   `gorm:"-" json:"coverUrl"`                                // 封面在oss中的url
	LabelIds     string   `gorm:"column:label_ids" json:"labelIds" form:"labelIds"` // 标签id
	LabelNames   []string `gorm:"-" json:"labelNames"`                              // 标签名
	LabelIdsArr  []int64  `gorm:"-" json:"labelIdsArr"`
	CoverKey     string   `gorm:"column:cover_key" json:"coverKey"`
	IsCreator    bool     `gorm:"-" json:"isCreator"`
	IsAdmin      bool     `gorm:"-" json:"isAdmin"`
	CharacterId  int64    `gorm:"-" json:"characterId"`
	IsMember     bool     `gorm:"-" json:"isMember"` // 是否是成员
	BotOn        bool     `gorm:"column:bot_on;->" json:"-"`
	GreatSuccess int32    `gorm:"column:great_success;->" json:"-"`
	GreatFail    int32    `gorm:"column:great_fail;->" json:"-"`
	BindScriptId int64    `gorm:"column:bind_script_id" json:"bindScriptId"`
}

func (Room) TableName() string {
	return "room"
}

type RoomUser struct {
	common_entity.BaseEntity
	RoomId      int64  `gorm:"column:room_id" json:"roomId"`
	Uid         string `gorm:"column:uid" json:"uid"`
	Status      int32  `gorm:"column:status" json:"status"`
	CharacterId int64  `gorm:"column:character_id" json:"characterId"`
}

func (RoomUser) TableName() string {
	return "room_user"
}

type SystemMessage struct {
	common_entity.BaseEntity
	Uid     string `gorm:"column:uid" json:"uid"`
	Message string `gorm:"column:message" json:"message"`
}

func (SystemMessage) TableName() string {
	return "system_message"
}

type ForumTopic struct {
	common_entity.BaseEntity
	Topic        string                  `gorm:"column:topic" json:"topic" form:"topic"`
	Content      string                  `gorm:"-" json:"content" form:"content"` // 新建时自带的一条内容
	PicFiles     []*multipart.FileHeader `gorm:"-" json:"-" form:"-"`
	PicCount     int64                   `gorm:"-" json:"picCount" form:"picCount"`
	IsLocked     string                  `gorm:"column:is_locked;default:'N'" json:"isLocked"`
	LikeCount    int64                   `gorm:"column:like_count;default:0" json:"likeCount"`
	CollectCount int64                   `gorm:"column:collect_count;default:0" json:"collectCount"`
	CreatorName  string                  `gorm:"-" json:"creatorName"`
	IsCreator    bool                    `gorm:"-" json:"isCreator"`
	IsLiked      bool                    `gorm:"-" json:"isLiked"`     // 查询者是否点赞
	IsCollected  bool                    `gorm:"-" json:"isCollected"` // 查询者是否收藏
}

func (ForumTopic) TableName() string {
	return "forum_topic"
}

type ForumContent struct {
	common_entity.BaseEntity
	TopicId       int64                   `gorm:"column:topic_id" json:"topicId" form:"topicId"`
	Content       string                  `gorm:"column:content" json:"content" form:"content"`
	PicsStr       string                  `gorm:"column:pics" json:"-"`
	PicCount      int64                   `gorm:"-" json:"picCount" form:"picCount"`
	Pics          []string                `gorm:"-" json:"pics"`
	PicFiles      []*multipart.FileHeader `gorm:"-" json:"picFiles"`
	LikeCount     int64                   `gorm:"column:like_count;default:0" json:"likeCount"`
	CreatorName   string                  `gorm:"-" json:"creatorName"`
	CreatorAvatar string                  `gorm:"-" json:"creatorAvatar"`
	IsCreator     bool                    `gorm:"-" json:"isCreator"`
	IsLiked       bool                    `gorm:"-" json:"isLiked"` // 查询者是否点赞
}

func (ForumContent) TableName() string {
	return "forum_content"
}

type ForumReply struct {
	common_entity.BaseEntity
	ContentId     int64  `gorm:"column:content_id" json:"contentId"`
	Content       string `gorm:"column:content" json:"content"`
	ReplyUser     string `gorm:"column:reply_user" json:"replyUser"`
	CreatorName   string `gorm:"-" json:"creatorName"`
	CreatorAvatar string `gorm:"-" json:"creatorAvatar"`
	ReplyUserName string `gorm:"-" json:"replyUserName"`
}

func (ForumReply) TableName() string {
	return "forum_reply"
}

type ForumTopicLikeCollection struct {
	common_entity.BaseEntity
	TopicId int64  `gorm:"column:topic_id" json:"topicId"`
	Uid     string `gorm:"column:uid" json:"uid"`
	Type    int32  `gorm:"column:type" json:"type"`
}

func (ForumTopicLikeCollection) TableName() string {
	return "forum_topic_like_collection"
}

type ForumContentLike struct {
	common_entity.BaseEntity
	ContentId int64  `gorm:"column:content_id" json:"contentId"`
	Uid       string `gorm:"column:uid" json:"uid"`
}

func (ForumContentLike) TableName() string {
	return "forum_content_like"
}

type RoomMessage struct {
	Id          int64           `gorm:"column:id;primaryKey" json:"id"`
	IsDeleted   string          `gorm:"column:is_deleted;default:N" json:"isDeleted" form:"isDeleted"`
	Creator     string          `gorm:"column:creator" json:"senderId" form:"creator"`
	Modifier    string          `gorm:"column:modifier" json:"modifier" form:"modifier"`
	GmtCreated  *time_util.Time `gorm:"column:gmt_created" json:"gmtCreated"`
	GmtModified *time_util.Time `gorm:"column:gmt_modified" json:"gmtModified"`
	RoomId      int64           `gorm:"column:room_id" json:"roomId"`
	CreatorName string          `gorm:"-" json:"username"`
	Avatar      string          `gorm:"-" json:"avatar"`
	Content     string          `gorm:"column:content" json:"content"`
	Files       []File          `gorm:"-" json:"files"`
	FilesStr    string          `gorm:"column:files" json:"filesStr"`
	TimeStamp   string          `gorm:"-" json:"timeStamp"`
	Date        string          `gorm:"-" json:"date"`
}

func (RoomMessage) TableName() string {
	return "room_message"
}

type File struct {
	Name string `json:"name"`
	Type string `json:"type"`
	Url  string `json:"url"`
	Path string `json:"path"`
}
